package com.service.atf.reply.service;

import com.service.atf.base.exception.TFException;
import com.service.atf.base.model.Account;
import com.service.atf.base.model.TFDraw;
import com.service.atf.base.utils.ATFConstants;
import com.service.atf.base.utils.ATFLogger;
import com.service.atf.reply.ac.AccountManager;
import com.service.atf.reply.core.IReadExecutor;

import java.util.Map;

/**
 * User: luotao
 * Date: 12-3-21
 * Time: 19:16:00
 */
public class DrawService3 implements IReadExecutor<TFDraw> {
    @Override
    public boolean isNotify() {
        return true;
    }

    private static final String KEY_BALC_CHARGE = "balcCharge";

    private static final String KEY_BALC_AWARD = "balcAward";

    public void initOut(Map out) {
        out.put(KEY_BALC_CHARGE, 0);
        out.put(KEY_BALC_AWARD, 0);
    }

    @Override
    public void execute(boolean recover, AccountManager accountManager, TFDraw draw, Map out) {
        // Validata.validataCustomerCode(this, draw.getCustomerCode());
        Account account = accountManager.getBussAccount(draw.getCustomerCode());

        //Validata.validataACNull(this, draw.getCustomerCode(), account);
        //�����˻�����
        if (account.getBalcAward() < draw.getAwardTradeMoney()) {
            String msg = "�û������˻�����" + draw.getCustomerCode();
            ATFLogger.syserr(msg);
            throw new TFException(ATFConstants.ATF_DRAW_MONEY, msg);
        }
        account.setBalcAward(account.getBalcAward() - draw.getAwardTradeMoney());
        accountManager.updateAccount(account);
        out.put(KEY_BALC_CHARGE, account.getBalcCharge());
        out.put(KEY_BALC_AWARD, account.getBalcAward());
    }
}
